<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="smvc" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${smvc}/css/bootstrap/bootstrap.min.css" rel="stylesheet">
<script src="${smvc}/js/jquery-3.1.1.js"></script>
<script src="${smvc}/js/bootstrap/bootstrap.min.js"></script>
<title>代码块列表</title>
</head>
<style>
h1 {
	color: #0099cc;
}
</style>
<body>
	<div class="page-header text-center">
		<h3 class="text-info">代码块列表</h3>
	</div>

	<!-- 页面主体 -->
	<div style="width: 80%; margin: auto;">
		<!-- 按钮组 -->
		<form class="form-inline" role="form">
			<input type="text" class="form-control" id="blockName"
				placeholder="请输入名称">
			<div class="btn-group">
				<button type="button" class="btn btn-info" id="serach">查找</button>
				<button type="button" class="btn btn-info" id="add">新增</button>
				<button type="button" class="btn btn-info" id="delete">删除</button>
			</div>
		</form>

		<!-- 列表 -->

		<table class="table table-bordered table-condensed">
			<thead>
				<th>*</th>
				<th>序号</th>
				<th>代码块名称</th>
				<th>备注</th>
				<th>操作</th>
			</thead>
			<c:forEach items="${codeList}" var="code" varStatus="s">
				<tr>
					<td width="20px">
						<div class="checkbox">
							<label><input type="checkbox" value="${code.id}">
							</label>
						</div>
					</td>
					<td width="30px">${s.index+1}</td>
					<td>${code.blockName}</td>
					<td>${code.remark}</td>
					<td width="120px">
						<button type="button" class="btn btn-info"
							onclick="update('${code.id}')">修改</button>
					</td>
				</tr>
			</c:forEach>
		</table>
	</div>

</body>
</html>
<script>
	$(function() {
		$("#add").bind("click", add)
		$("#delete").bind("click", deleteFun)
	})

	//新增代码块
	function add() {
		window.location.href="http://localhost:8080/SSM/codeBlock/edit?dataTime="+new Date().getTime();
	}
	
	//修改代码块
	function update(id){
		window.location.href="http://localhost:8080/SSM/codeBlock/edit?dataTime="+new Date().getTime()+"&id="+id;
		
	}
	//删除
	function deleteFun(){
		//被选中的代码块
		var checkBox = $("input[type='checkbox']:checked");
		var ids="";
		for(var i = 0; i< checkBox.length; i++){
			ids += $(checkBox[i]).val() + ",";
		}
		
		if("" == ids){
			alert("您没有选择任何删除的内容");
			return;
		}
		ids = ids.substring(0,ids.length -1)
		
		window.location.href="http://localhost:8080/SSM/codeBlock/delete?dataTime="+new Date().getTime()+"&ids="+ids;
		
	}
</script>
